//
//  AddressTableViewCell.m
//  MaiMaiGo
//
//  Created by 孙鹏飞 on 2017/4/7.
//  Copyright © 2017年 qian. All rights reserved.
//

#import "AddressTableViewCell.h"
#import "MGAddress.h"

@interface AddressTableViewCell ()

@property (weak, nonatomic) IBOutlet UILabel *delivery_nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *delivery_phoneLabel;
@property (weak, nonatomic) IBOutlet UILabel *delivery_addressLabel;

@property (weak, nonatomic) IBOutlet UIButton *is_defaultBtn;
@property (weak, nonatomic) IBOutlet UIButton *editBtn;
@property (weak, nonatomic) IBOutlet UIButton *deleteBtn;

@end

@implementation AddressTableViewCell

+(instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString * ID = @"address";
    AddressTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self) owner:nil options:nil] lastObject];
    }
    // 取消cell选中的颜色
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.selectionStyle = UITableViewCellSelectionStyleNone;
}

- (void)setAddress:(MGAddress *)address
{
    _address = address;
    _delivery_nameLabel.text = _address.consignee;
    _delivery_phoneLabel.text = _address.consignee_tel;
    _delivery_addressLabel.text = [NSString stringWithFormat:@"%@%@%@%@",_address.province,_address.city,_address.county,_address.address];
    _is_defaultBtn.selected = _address.is_default;
}

- (IBAction)defaultBtnClicked:(id)sender { // 设为默认按钮点击
    if ([_delegate respondsToSelector:@selector(AddressTableViewCell:DidClickedIs_defaultBtnAtIndexPath:)]) {
        [_delegate AddressTableViewCell:self DidClickedIs_defaultBtnAtIndexPath:_indexpath];
    }
}

- (IBAction)editBtnClicked:(id)sender { // 编辑按钮点击
    if ([_delegate respondsToSelector:@selector(AddressTableViewCell:DidClickedEditBtnAtIndexPath:)]) {
        [_delegate AddressTableViewCell:self DidClickedEditBtnAtIndexPath:_indexpath];
    }
}

- (IBAction)deleteBtnClicked:(id)sender {
    if ([_delegate respondsToSelector:@selector(AddressTableViewCell:DidClickedDeleteBtnAtIndexPath:)]) {
        [_delegate AddressTableViewCell:self DidClickedDeleteBtnAtIndexPath:_indexpath];
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
